package com.example.hcbmsm.service.impl;

import com.auth0.jwt.interfaces.Claim;
import com.example.hcbmsm.domain.Mr;
import com.example.hcbmsm.domain.MrExample;
import com.example.hcbmsm.domain.PatExample;
import com.example.hcbmsm.mapper.MrMapper;
import com.example.hcbmsm.service.MrService;
import com.example.hcbmsm.util.HCBMSMResult;
import com.example.hcbmsm.util.JavaWebToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * @author Xinghm
 * @version 1.0
 * @since 2024/10/31 19:44
 */
@Service
public class MrServiceImpl implements MrService {
    @Autowired
    private MrMapper mrMapper;

    @Override
    public Map add(String token, Mr mr) {
        Map<String, Claim> tokenInfo = JavaWebToken.getTokenInfo(token);
        Long docId = new Long(tokenInfo.get("docId").asString());
        mr.setDocId(docId);
        if (mrMapper.insertSelective(mr) == 1) {
            return HCBMSMResult.SUCCESS();
        }
        return HCBMSMResult.ERROR();
    }

    @Override
    public Map getListByPatId(String token) {
        Map<String, Claim> tokenInfo = JavaWebToken.getTokenInfo(token);
        Long patId = new Long(tokenInfo.get("patId").asString());
        return HCBMSMResult.SUCCESS(mrMapper.selectMrListByPatId(patId));
    }
}
